﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

using OVS.Business;
using OVS.CoreDomain;
using OVS.CoreDomain.Business;


namespace OVS
{
    public partial class SearchElections : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (Session["LoggedIn"] == null)
            {
                Response.Write("Please login!");
                Response.End();
            }
            else
            {
                ILoggedin loggedIn = (ILoggedin)Session["LoggedIn"];
                if (!loggedIn.IsAdmin)
                {
                    Response.Write("You must be logged in as Admin to view this page!");
                    Response.End();
                }
            }

            if (!Page.IsPostBack)
            {
                IBusinessElection businessElection = new BusinessElection();
                IList<IElection> elections = businessElection.GetElections();
                gvResults.DataSource = elections;
                gvResults.DataBind();


            }
        }

        protected void gvResults_OnRowCommand(object sender, GridViewCommandEventArgs e)
        {
            string electionId;

            switch (e.CommandName)
            {
                case "EditElection":
                    electionId = e.CommandArgument.ToString();
                    Response.Redirect("ManageElections.aspx?Mode=Edit&ElectionId=" + electionId);
                    break;

            }
        }
    }
}
